package com.qingcloud.adminbackend.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.constant.WamingConstant;
import com.qingcloud.adminbackend.entity.equipment.ProductionStateDTO;
import com.qingcloud.adminbackend.entity.equipment.ProductionStateVO;
import com.qingcloud.adminbackend.mapper.SysEquipmentMapper;
import com.qingcloud.adminbackend.service.IProductionStateService;
import com.qingcloud.adminbackend.utils.ImportFileUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class ProductionStateServiceImpl implements IProductionStateService {

    @Resource
    SysEquipmentMapper sysEquipmentMapper;


    @Override
    public IPage<ProductionStateVO> findProductionStatePage(ProductionStateDTO dto) {
        Page<ProductionStateDTO> page = new Page<>(dto.getCurrentPage(), dto.getPerPage());
        return sysEquipmentMapper.findProductionStatePage(page, dto);
    }

    @Override
    public AjaxResult importFile(MultipartFile excelFile) throws Exception {
        List<String> equipmentIdList = new ArrayList<>();
        AjaxResult ajaxResult = ImportFileUtil.parserEquipmentIdForExcel(excelFile.getInputStream(), equipmentIdList);
        if(!WamingConstant.SUCCESS.equals(ajaxResult.getErroCode())){
            return ajaxResult;
        }
        //生产测试完成，修改状态为2
        sysEquipmentMapper.updateStandardFlag(2, equipmentIdList);
        return new AjaxResult(WamingConstant.SUCCESS, "处理成功", null);
    }
}
